const { getCode } = require("../utils/api")

// custom-tab-bar/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {


  },

  /**
   * 组件的初始数据
   */
  data: {
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#3B3A3F",
    list: [{
      "pagePath": "/pages/homepage/home",
      "iconPath": "../static/tabbar/homeicon.png",
      "selectedIconPath": "../static/tabbar/homeicon_select.png",
      "text": "首页",
      "number": ''
    },
    {
      "pagePath": "/pages/shoppage/shop",
      "iconPath": "../static/tabbar/shopicon.png",
      "selectedIconPath": "../static/tabbar/shopicon_select.png",
      "text": "商城",
      "number": ''
    },
    {
      "pagePath": "",
      "iconPath": "https://qmtestimage.oss-cn-guangzhou.aliyuncs.com/saomaicon.png",
      "selectedIconPath": "https://qmtestimage.oss-cn-guangzhou.aliyuncs.com/saomaicon.png",
      "text": "",
      "number": ''
    },
    {
      "pagePath": "/pages/picpage/index",
      "iconPath": "../static/tabbar/picicon.png",
      "selectedIconPath": "../static/tabbar/picicon_select.png",
      "text": "图鉴",
      "number": ''
    },

    {
      "pagePath": "/pages/minepage/index",
      "iconPath": "../static/tabbar/myicon.png",
      "selectedIconPath": "../static/tabbar/myicon_select.png",
      "text": "我的",
      "number": ''
    }],
    background: '../static/tabbar/tabbarbg.png',
    centerImg: 'https://qmtestimage.oss-cn-guangzhou.aliyuncs.com/icon-saoyisao.png',
    centerTitle: 'https://qmtestimage.oss-cn-guangzhou.aliyuncs.com/saoma-wenzi.png',
    showModal: false,
    fatherData: {},
    showErrModal: false,
    errData: '',
  },


  /**
   * 组件的方法列表
   */
  methods: {
    switchTab(e) {
      let that = this
      if (e.currentTarget.dataset.index != 2) {
        const path = e.currentTarget.dataset.path
        wx.switchTab({
          url: path,
        })
      } else {
        this.getScanCode()
      }
    },

    // //扫码方法
    getScanCode() {
      wx.navigateTo({
        url: '/component/camerapage/index',
      });
      return
      let that = this
      wx.scanCode({
        success(res) {
          if (res.result) {
            let resStr = res.result
            let strIndex = resStr.indexOf('goodsurl=') + 9
            let resParams = resStr.substr(strIndex)
            that.getCodeMsg(resParams)
          }
        }
      })
    },
    // codeRes(res) {

    //   if (res) {
    //     let resStr = res
    //     let strIndex = resStr.indexOf('goodsurl=') + 9
    //     let resParams = resStr.substr(strIndex)
    //     this.getCodeMsg(resParams)
    //   }
    // },


    //获取二维码数据
    // async getCodeMsg(url) {
    //   let params = {
    //     goodsurl: url
    //   }
    //   await getCode(params).then((res) => {

    //     if (res.errcode == 0) {
    //       this.setData({
    //         showModal: true,
    //         fatherData: res.data,
    //         "fatherData.numRes": res.data.canscore * Number(res.data.multiplier),
    //         "fatherData.nexttime": (res.data.nexttime).substring(0, 10),
    //         "fatherData.endtime": (res.data.endtime).substring(0, 10),
    //         "fatherData.goodsurl": url
    //       })
    //     } else {
    //       this.setData({
    //         showErrModal: true,
    //         errData: res.errmsg
    //       })

    //     }
    //   })
    // },

  }
})
